package org.dfl.plugin.dialogs;

import org.dfl.core.model.transitions.ExecTransition;
import org.dfl.messages.Messages;
import org.dfl.plugin.editor.model.TransitionModelElement;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;

/**
 * dialog to change execTransition properties
 * @author Piotr Wlodarczyk
 *
 */
public class ExecTransitionPropertiesDialog extends TransitionPropertiesDialog {
	private Text commandField;
	private Text dirField;
	public ExecTransitionPropertiesDialog(TransitionModelElement t) {
		super(t);
	}

	@Override
	protected void addSpecificTransitionElements(final Shell parent){
		if(getTransition() instanceof ExecTransition){
			ExecTransition transition = (ExecTransition) getTransition() ;

			//	add command
			commandField = addStringRow(parent, true, false, Messages.ExecTransitionPropertiesDialog_command, transition.getCommand());
			commandField.addModifyListener(new ModifyListener(){
				public void modifyText(ModifyEvent e) {
					setFieldErrorChecking(commandField, commandField.getText()==null || commandField.getText().equals(""), Messages.ExecTransitionPropertiesDialog_errorEmptyCommand); //$NON-NLS-1$
				}});
			addEnterKeyListener(commandField);

			
			//	add dir
			dirField = addDirSelectionRow(parent, false, false, Messages.ExecTransitionPropertiesDialog_directory, transition.getDir());
			addEnterKeyListener(dirField);
		}
	}
	
	
	@Override
	protected void finish() {
		super.finish();
		getTransition().setCommand(commandField.getText());
		getTransition().setDir(dirField.getText());
	}
	
	@Override
	public ExecTransition getTransition() {
		return (ExecTransition) super.getTransition();
	}
}
